function Pane() {
  this.filePath = "";
  this.saved = false;
  this.initialized = false;
}

// Add XUL for new pane to window
Pane.prototype.construct = function() {
  // Create new elements
  var newTab = document.createElementNS(XUL_NS, "tab");
  var newTabpanel = document.createElementNS(XUL_NS, "tabpanel");
  var newTextbox = document.createElementNS(XUL_NS, "textbox");
  
  // Set appropriate properties
  newTab.setAttribute("label", "New");
  newTextbox.setAttribute("multiline", "true");
  newTextbox.setAttribute("flex", "1");
  newTextbox.setAttribute("class", "editor-text");
  newTextbox.setAttribute("onkeypress", "avocet.textChange()");
  
  // Add to window
  document.getElementById("tabs").appendChild(newTab);
  document.getElementById("tabpanels").appendChild(newTabpanel);
  newTabpanel.appendChild(newTextbox);
  
  return this;
}

// Remove XUL for active pane from window
Pane.prototype.destroy = function() { 
  // Select elements to remove
  var removeTab = avocet.getTab(avocet.getSelectedTabIndex());
  var removeText = avocet.getTextbox(avocet.getSelectedTabIndex());
  var removePanel = avocet.getPanel(avocet.getSelectedTabIndex());
  
  // Select tab to right
  var newIndex = avocet.getSelectedTabIndex();
  if(avocet.getSelectedTabIndex() == avocet.lastTab + 1) {
    // Select last tab it rightmost tab was closed
    newIndex = avocet.lastTab;
  }
  document.getElementById("tabbox").selectedIndex = newIndex;
  
  // Remove elements
  removePanel.removeChild(removeText);
  document.getElementById("tabs").removeChild(removeTab);
  document.getElementById("tabpanels").removeChild(removePanel) 
}

// Get file name from file path
Pane.prototype.getFileName = function() { 
  if(this.getFilePath().indexOf('/') != -1) {
    // For Linux and Mac
    var pathSplit = this.getFilePath().split('/');
  } else {
    // For windows
    var pathSplit = this.getFilePath().split('\\');      
  }
  return pathSplit[pathSplit.length - 1];
}

// Get value of active text box
Pane.prototype.getText = function() {
  var selectedText = avocet.getTextbox(avocet.getSelectedTabIndex());
  return selectedText.value;
}

// Set value of active text box
Pane.prototype.setText = function(newText) {
  var selectedText = avocet.getTextbox(avocet.getSelectedTabIndex());
  selectedText.value = newText;
}

// Get file path of active pane
Pane.prototype.getFilePath = function() { return this.filePath; }

// Set file path of active pane
Pane.prototype.setFilePath = function(path) { this.filePath = path; }

// Get file saved state (true if file has been saved, false if not)
Pane.prototype.getSaved = function() { return this.saved; }

// Set file saved state (boolean)
Pane.prototype.setSaved = function(newState) { this.saved = newState; }

// Get file created state
Pane.prototype.getInitialized = function() { return this.initialized; }

// Set file created state
Pane.prototype.setInitialized = function(newState) { this.initialized = newState; }
